package Ex615;

import java.util.Random;
/**
* @Description: 狗互相咬测试类
*/
public class Test {

    public static void main(String[] args) {
        Animal myDog = new Dog("myDog");
        Animal yourDog = new Dog("yourDog");
        System.out.println("myDog pk yourDog");
        if (myDog instanceof Dog) {
            ((Dog) myDog).bark();
        }
        if (yourDog instanceof Dog) {
            ((Dog) yourDog).bark();
        }
        dogBite(myDog, yourDog);  //调用狗咬狗的方法
    }

    public static void dogBite(Animal dog1, Animal dog2 ) {
        while (dog2.blood > 0 && dog1.blood > 0) {//循环咬，直到一只dog dead
            Random random = new Random();
            int hurt = random.nextInt(15);//设定一个伤害的随机数
            if (hurt%2==0) {//当伤害是偶数 dog1 bite dog2
				dog1.bite(dog2, hurt);
            }else {
				dog2.bite(dog1, hurt);
            }
        }
    }
}
